/*
 *  Smoothing filter
 *  
 *  coefficients are depended from sampling rate
 */

#ifndef __SMOOTH_H__
#define __SMOOTH_H__

//
// TimeConstant = 0.5 sec
// SamplingTime = 0.001
//
// k = exp(-SamplingTime/TimeConstant) = 0.998
// 1-k = 0.002
//
static __inline double Smooth(double input, double* z)
{
    *z = 0.998*(*z) + 0.002*input;
    return *z;
}

//
// k = (2^SMOOTHCOEFF-1)/(2^SMOOTHCOEFF)
//
// SMOOTHCPEFF = 9
// k = 511/512 = 0.998
//

#define SMOOTHCOEF  9

static __inline L1_INT32 Smooth32(L1_INT32 input, L1_INT32* z)
{
//    *z -= (*z - (input << SMOOTHCOEF)) >> SMOOTHCOEF;
//    return *z >> SMOOTHCOEF;

    *z -= (*z - input) >> SMOOTHCOEF;
    return *z;
}

#endif // __SMOOTH_H__
